/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AIproccess;

import Army.building.Building;
import Army.ComputerTeam;
import GameObject.LayerManager;
import java.awt.Point;
import java.util.Random;

/**
 *
 * @author Huy
 */
public class PlayerAI extends Thread {

	protected LayerManager layer;
	protected ComputerTeam team;
	protected boolean isPlay = true;
	protected boolean isPause = false;
	protected int delay = 500;
	public static Random RANDOM = new Random(System.currentTimeMillis());

	public PlayerAI(LayerManager layer, ComputerTeam team) {
		this.layer = layer;
		this.team = team;
	}

	public boolean isIsPlay() {
		return isPlay;
	}

	public void setIsPlay(boolean isPlay) {
		this.isPlay = isPlay;
	}

	public boolean isIsPause() {
		return isPause;
	}

	public void setIsPause(boolean isPause) {
		this.isPause = isPause;
	}
	
	protected void fixPosition(Building building) {
		Point p = new Point();
		p.x = (int) (building.getPosition().x / layer.getMap().getCellWidth())
				* layer.getMap().getCellWidth() + building.getSize() / 2;
		p.y = (int) (building.getPosition().y / layer.getMap().getCellHeight())
				* layer.getMap().getCellHeight() + building.getSize() / 2;
		building.setPosition(p);
	}

	@Override
	public void run() {
		int i = 0;
		while (isPlay && team.isAlive()) {
			if (!isPause) {
				proccess();
			}
			try {
				sleep((int) (delay));
			} catch (InterruptedException e) {
			}
		}
		System.out.println("DONE! " + getName());
	}

	protected void proccess() {
	}
}
